import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Scanner;

public class JennaKingsburyA3client {
	private static ArrayList<NetworkNode> dvsList;
	public static Socket inFromServer;
	public static Scanner dvrData;

	public static void main(String[] args) throws IOException {
		dvrData = new Scanner(new File("DVR.txt"));
		String message = "";

		// Create socket that connects to the local host.
		Socket clientSocket = new Socket("localhost", 33445);
		// Set up our output stream, which we will use to send -webAddress- to the localhost.
		DataOutputStream outToServer = new DataOutputStream(
				clientSocket.getOutputStream());

		// Loop this section:
		// -Read a line from DVR.txt and store it in "message"
		// Send our message to the localhost.
		// Wait for localhost to send a "ready" string back.
		boolean sending = true;

		int i = 0;
		while (sending) {
			message = readNextDVRLine();
			if (message == null || message == "") {
				sending = false;
			} else {
				outToServer.writeBytes(message + "\n");
				System.out.print("We just sent:" + message);
			}
			System.out.println();
		}

		// Close the socket
		clientSocket.close();

	}

	public static String readNextDVRLine() throws IOException {
		String returnString = "";
		if (dvrData.hasNextLine()) {
			returnString += dvrData.nextLine().trim();
			System.out.println("We just read in:" + returnString);
		}
		return returnString;
	}

}
